﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Codeplex.Reactive;
using HelloWorld.Common;
using System.Reactive.Linq;

namespace HelloWorld.DisplayModule
{
    public class DisplayViewModel : IPartImportsSatisfiedNotification
    {
        [Import]
        public DisplayModel Model { get; set; }

        public ReactiveProperty<ReactiveCollection<DisplayItemViewModel>> DisplayItems { get; private set; }

        public DisplayViewModel()
        {
            this.DisplayItems = new ReactiveProperty<ReactiveCollection<DisplayItemViewModel>>();
        }

        public void OnImportsSatisfied()
        {
            this.DisplayItems.Value = this
                .Model
                .DisplayText
                .Where(text => !string.IsNullOrWhiteSpace(text))
                .Select(text => new DisplayItemViewModel(text))
                .ToReactiveCollection();
        }
    }
}
